<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑劳动合同</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>人员</label>
                        <div class="layui-input-block">
                            <input type="text" id="arcid_name" readonly placeholder="请输入" autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">劳动合同编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>合同期限类型</label>
                        <div class="layui-input-block">
                            <div id="tongtype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>期限起</label>
                        <div class="layui-input-block">
                            <input type="text" name="xiandt" id="xiandt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">期限止</label>
                        <div class="layui-input-block">
                            <input type="text" name="xianzhidt" id="xianzhidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">试用期起</label>
                        <div class="layui-input-block">
                            <input type="text" name="shidt" id="shidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">试用期止</label>
                        <div class="layui-input-block">
                            <input type="text" name="shizhidt" id="shizhidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">试用工资(元/月)</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongfee" id="gongfee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">转正工资(元/月)</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhuanfee" id="zhuanfee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同性质</label>
                        <div class="layui-input-block">
                            <select id="nature" name="nature" lay-filter="nature" ></select>
                            <p class="error" id="nature_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">提前终止日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhongdt" id="zhongdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">签约日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="qiandt" id="qiandt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            xiandt: {required: true},
        },
        messages:{
            xiandt: {required: "请选择"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_archive_tong_edit,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $("#arcid_name").val(data.arcid_name);
                $("#number").val(data.number);
                $("#xiandt").val(data.xiandt);
                $("#xianzhidt").val(data.xianzhidt);
                $("#shidt").val(data.shidt);
                $("#shizhidt").val(data.shizhidt);
                $("#gongfee").val(data.gongfee);
                $("#zhuanfee").val(data.zhuanfee);
                $("#zhongdt").val(data.zhongdt);
                $("#qiandt").val(data.qiandt);
                $("#explain").val(data.explain);


                xmselect_dan('tongtype', res.data.tongtype, data.tongtype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#tongtype").find('xm-select').removeClass('error');
                    }else{
                        $("#tongtype").find('xm-select').addClass('error');
                    }
                });

                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(data.state == state[key]){
                        state_str += '<option value="'+state[key]+'" selected>'+state[key]+'</option>';
                    }else{
                        state_str += '<option value="'+state[key]+'">'+state[key]+'</option>';
                    }
                }
                $("#state").html(state_str);

                var nature_str = '<option value="">请选择</option>';
                var nature = res.data.nature;
                for (var key in nature){
                    if(data.nature == nature[key]){
                        nature_str += '<option value="'+nature[key]+'" selected>'+nature[key]+'</option>';
                    }else{
                        nature_str += '<option value="'+nature[key]+'">'+nature[key]+'</option>';
                    }
                }
                $("#nature").html(nature_str);





                public_upload_file_load('upload_files', res.data.files);
                initParseMoney();
                render_from();
            }
        });


        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(nature)', function(data){
            if(data.value == ''){
                $('#nature_error').show().text('请选择');
                $('#nature_error').parent().find('input').addClass('select_error');
            }else{
                $('#nature_error').hide();
                $('#nature_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            parseMoney(data);
            var validRes = $("#commentForm").valid();


            if(!data.field.tongtype){
                $("#tongtype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#tongtype").find('xm-select').removeClass('error');
            }

            if(data.field.state == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }

            if(data.field.nature == ''){
                $('#nature_error').show().text('请选择');
                $('#nature_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#nature_error').hide();
                $('#nature_error').parent().find('input').removeClass('select_error');
            }



            if(!validRes){return false;}


            data = parseMoney(data);

            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_archive_tong_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
